﻿using UnityEngine;
using UnityEngine.EventSystems;

public class WeaponJoystick : WorldJoystick, IPointerDownHandler, IPointerUpHandler, IDragHandler
{
    private readonly Vector2 _horMoveDir = new Vector2(60, 0);
    private readonly Vector2 _verMoveDir = new Vector2(0, 60);
    private Vector2 _lastKeyInputDir = Vector2.zero;

   


    #region Interface Implement
    public void OnPointerDown(PointerEventData eventData)
    {
        OnInputDown(eventData.pressPosition, eventData.position);

        float circleX = (eventData.pressPosition.x - Screen.width) / Screen.width * BaseTransform.rect.width * 2;
        float circleY = eventData.pressPosition.y / Screen.height * BaseTransform.rect.height;

        if (CircleTransform)
            CircleTransform.anchoredPosition3D = new Vector3(circleX, circleY, 0);

        if (KnobTransform)
            KnobTransform.anchoredPosition3D = new Vector3(0, 0, 0);
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        OnInputUp(eventData.pressPosition, eventData.position);
        if (CircleTransform) CircleTransform.anchoredPosition3D = new Vector3(-150, 150, 0);
        if (KnobTransform) KnobTransform.anchoredPosition3D = new Vector3(0, 0, 0);
    }

    public void OnDrag(PointerEventData eventData)
    {
        OnInputDrag(eventData.pressPosition, eventData.position);
        if (KnobTransform) KnobTransform.anchoredPosition3D = Vector2.ClampMagnitude(((eventData.position - eventData.pressPosition) / Screen.height * 750), 80);
    }
    #endregion
}
